capture log close

set matsize 5000


log using "LogFiles/WarsAndProsthesisPatentsAnalysisOfCountsEventStudies.log", replace



**** Assemble data for additional figures and regressions
use "Data/control_classes_CW.dta", clear
append using "Data/control_classes_WWI.dta"
merge 1:1 patnum using "Data/all_patents_basicinfo.dta"
keep if _merge == 3
drop _merge

tab iyear if nclassgoogle1 == 623


rename iyear year


gen patentcount = 1


collapse (sum) patentcount, by(nclassgoogle1 year)

tsset nclassgoogle1 year
tsfill

drop if year < 1850

gen eventyear = . 
replace eventyear = year - 1862 if year <= 1890
replace eventyear = year - 1915 if year > 1890


*** Generate a numeric variable for the individual war episodes
gen warepisode = .
replace warepisode = 1 if year >= 1840 & year <= 1890
replace warepisode = 2 if year >= 1890 & year <= 1940

egen class_by_episode = group(nclassgoogle1 warepisode)
egen class_by_episodecount = count(class_by_episode), by(class_by_episode)
tab class_by_episodecount if warepisode == 1
tab class_by_episodecount if warepisode == 2
keep if (class_by_episodecount == 40 & warepisode == 1) | (class_by_episodecount == 51 & warepisode == 2)

tsset class_by_episode eventyear

replace patentcount = 0 if patentcount == .
egen premeanpatentsperyearB = mean(patentcount) if eventyear < 0, by(class_by_episode)
egen premeanpatentsperyear = max(premeanpatentsperyearB), by(class_by_episode)

drop if premeanpatentsperyear <= 1

drop if eventyear < -12
drop if eventyear > 15

*** Create key treatment variable
gen prosthetics = 0
replace prosthetics = 1 if nclassgoogle1 == 623

*** Create Alternative Control Groups
gen medicalclass = 0
replace medicalclass = 1 if inlist(nclassgoogle1, 424, 514, 128, 600, 601, 602, 604, 606, 607, 435, 800, 351, 433, 623)
gen miscmechanical = 0
replace miscmechanical = 1 if inlist(nclassgoogle1, 7, 16, 42, 49, 51, 74, 81, 86, 89, 100, 124, 157, 184, 193, 194, 198, 212, 227, 235, 239, 254, 267, 291, 294, 384, 400, 402, 406, 411, 453, 454, 470, 482, 483, 492, 508)
gen metalworkmechanical = 0
replace metalworkmechanical = 1 if inlist(nclassgoogle1, 29, 72, 75, 76, 140, 147, 148, 163, 164, 228, 266, 270, 413, 419, 420)
gen materialprocessingmechanical = 0
replace materialprocessingmechanical = 1 if inlist(nclassgoogle1, 65, 82, 83, 125, 141, 142, 144, 173, 209, 221, 225, 226, 234, 241, 242, 264, 271, 407, 408, 409, 414, 425, 451, 493)

sum *

replace eventyear = eventyear + 100
fvset base 100 eventyear

// Generates Figure D.1
poisson patentcount i.prosthetics##i.eventyear i.eventyear##i.warepisode i.nclassgoogle1##i.warepisode , cluster(class_by_episode)
parmest, saving("Estimates/EventStudyBroadControls.dta", replace)

poisson patentcount i.prosthetics##i.eventyear i.eventyear##i.warepisode i.nclassgoogle1##i.warepisode if medicalclass == 1, cluster(class_by_episode)
parmest, saving("Estimates/EventStudyMedicalControls.dta", replace)



use "Estimates/EventStudyMedicalControls.dta", clear
rename estimate prostheticestimate
label var prostheticestimate "Prosthetics Patents"
label var min95 "Prosthetics Lower"
label var max95 "Prosthetics Upper"
drop z p stderr eq

keep if substr(parm,1,13) == "1.prosthetics"
replace parm = "1.prosthetics#100o.eventyear" if parm == "1.prosthetics"
replace max95 = 0 if parm == "1.prosthetics#100o.eventyear"
replace min95 = 0 if parm == "1.prosthetics#100o.eventyear"
replace prostheticestimate = 0 if parm == "1.prosthetics#100o.eventyear"

gen eventyear = .
lab var eventyear "Event Year"
gen eventyearB = ""
replace eventyearB = substr(parm,15,3)
replace eventyearB = substr(parm,15,2) if substr(parm,17,1) == "o"
destring eventyearB , gen(eventyearC)
replace eventyear = eventyearC - 100 
// generates Figure D.1 
graph twoway scatter prostheticestimate eventyear if eventyear >= -12 & eventyear <= 12, || ///
	lfit prostheticestimate eventyear if eventyear >= -12 & eventyear <= 0, lpattern(dash)  || ///
	rcap min95 max95 eventyear if eventyear >= -12 & eventyear <= 12,  ///
 xline(0, lcolor(black) lpattern(dash)) ///
 yline(0, lcolor(black)) ///
 title("Other Medical Controls", size(medlarge)) ///
 ylabel(-2 "-2" -1 "-1" 0.0 "0.0"  1 "1" 2 "2") ///
 legend(order(1 "Prosthetic Patenting Rate" 2 "Trend through Baseline Estimates") rows(1)) ///
 xtitle("") ytitle("Change in Patenting Rate") graphregion(color(white)) /// 
 xlabel(-12(6)12, labsize(medsmall)) xscale(range(-12 12)) ///
 name(EventStudyMedicalControls, replace)

graph export "Figures/EventStudyMedicalControls.pdf", name(EventStudyMedicalControls)  replace

 
use "Estimates/EventStudyBroadControls.dta", clear
rename estimate prostheticestimate
label var prostheticestimate "Prosthetics Patents"
label var min95 "Prosthetics Lower"
label var max95 "Prosthetics Upper"
drop z p stderr eq

keep if substr(parm,1,13) == "1.prosthetics"
replace parm = "1.prosthetics#100o.eventyear" if parm == "1.prosthetics"
replace max95 = 0 if parm == "1.prosthetics#100o.eventyear"
replace min95 = 0 if parm == "1.prosthetics#100o.eventyear"
replace prostheticestimate = 0 if parm == "1.prosthetics#100o.eventyear"

gen eventyear = .
lab var eventyear "Event Year"
gen eventyearB = ""
replace eventyearB = substr(parm,15,3)
replace eventyearB = substr(parm,15,2) if substr(parm,17,1) == "o"
destring eventyearB , gen(eventyearC)
replace eventyear = eventyearC - 100 
// generates Figure D.1 
graph twoway scatter prostheticestimate eventyear if eventyear >= -12 & eventyear <= 12,  || ///
	lfit prostheticestimate eventyear if eventyear >= -12 & eventyear <= 0, lpattern(dash)  || ///
	rcap min95 max95 eventyear if eventyear >= -12 & eventyear <= 12,  ///
 xline(0, lcolor(black) lpattern(dash)) ///
 yline(0, lcolor(black)) ///
 title("Broadest Set of Controls", size(medlarge)) ///
 ylabel(-2 "-2" -1 "-1" 0.0 "0.0"  1 "1" 2 "2") ///
 legend(order(1 "Prosthetic Patenting Rate" 2 "Trend through Baseline Estimates") rows(1)) ///
 xtitle("") ytitle("Change in Patenting Rate") graphregion(color(white)) /// 
 xlabel(-12(6)12, labsize(medsmall)) xscale(range(-12 12)) ///
 name(EventStudyBroadControls, replace)

 graph export "Figures/EventStudyBroadControls.pdf", name(EventStudyBroadControls)  replace

	
 

capture log close
